/**
 * Created by Administrator on 2017/9/4.
 */
var category = {
    form: null,
    name: null,
    desc: null,
    sort_no: null,
    pid: null,

    init: function () {
        category.initBind();
        category.initEvent();
    },

    initBind: function () {
        category.form = $("form");
        category.name = $('#category-name');
        category.desc = $('#category-desc');
        category.sort_no = $('#category-sort_no');
        category.pid = $('#category-pid');
    },

    initEvent: function () {
        category.name.change(function () {
            var name = $('#category-name').val();
            var reg = new RegExp('[a-zA-z]+://[^\\s]*');
            if (name.match(reg)) {
                $.ajax({

                    name: '/category/get-category',
                    type: 'post',
                    dataType: 'json',
                    data: {'name': name},
                    success: function (data) {
                        console.log(data);
                        category.name.val(data.name);
                        category.desc.val(data.desc);
                    },
                    error: function () {
                        category.name.val('');
                        category.desc.val('');
                    },
                });
            } else {

                category.name.val('');
                category.desc.val('');
            }
        });
    },

};
$(function () {
    category.init();
});